local juebing = fk.CreateSkill{
  name = "hanqing__juebing",
}

Fk:loadTranslationTable{
  ["hanqing__juebing"] = "谲兵",
  [":hanqing__juebing"] = "当你指定或成为伤害牌的目标后，你可以对其中一名目标角色造成1点伤害，若如此做，此牌结算后，其可以弃置至多两张牌，"..
  "回复等量的体力。",

  ["#hanqing__juebing-choose"] = "谲兵：对其中一名目标角色造成1点伤害，此牌结算后其可以弃置至多两张牌回复等量体力",
  ["#hanqing__juebing-discard"] = "谲兵：你可以弃置至多两张牌，回复等量的体力",
}

local spec = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(juebing.name) and
      (event == fk.TargetSpecified and data.firstTarget or event == fk.TargetConfirmed) and
      data.card.is_damage_card and table.find(data.use.tos, function (p)
        return not p.dead
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = data.use.tos,
      skill_name = juebing.name,
      prompt = "#hanqing__juebing-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    data.extra_data = data.extra_data or {}
    data.extra_data.hanqing__juebing = data.extra_data.hanqing__juebing or {}
    table.insertIfNeed(data.extra_data.hanqing__juebing, to.id)
    room:damage{
      from = player,
      to = to,
      damage = 1,
      skillName = juebing.name,
    }
  end,
}
juebing:addEffect(fk.TargetSpecified, spec)
juebing:addEffect(fk.TargetConfirmed, spec)

juebing:addEffect(fk.CardUseFinished, {
  anim_type = "support",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.hanqing__juebing and
      table.contains(data.extra_data.hanqing__juebing, player.id) and
      not player.dead and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(player, {
      min_num = 1,
      max_num = 2,
      include_equip = true,
      skill_name = juebing.name,
      prompt = "#hanqing__juebing-discard",
      cancelable = true,
      skip = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    room:throwCard(cards, juebing.name, player, player)
    if not player.dead then
      room:recover{
        who = player,
        num = #cards,
        recoverBy = player,
        skillName = juebing.name,
      }
    end
  end,
})

return juebing
